Do predictor=2 differencing at sample width, not byte width#1498
Merged
brendancol merged 2 commits intomainfrom May 6, 2026
Merged
Do predictor=2 differencing at sample width, not byte width#1498brendancol merged 2 commits intomainfrom
brendancol merged 2 commits intomainfrom
Conversation
TIFF predictor=2 differences adjacent same-component samples at the sample's natural bit width. The CPU and GPU code was differencing byte-wise instead, which drops the inter-byte carry for samples wider than one byte. uint8 was fine because a sample fits in one byte. uint16, int16, uint32, int32 silently came out wrong. What broke: - Reading a uint16/int16/uint32/int32 TIFF written with predictor=2 by libtiff, GDAL, rasterio, or tifffile gave garbage (off by tens of LSBs for typical data). - Writing such a file from xrspatial produced output other libraries decoded as garbage. The xrspatial round-trip happened to work because both ends shared the same broken arithmetic. Fix: rework predictor_decode/predictor_encode on CPU and GPU to view the buffer as the matching unsigned dtype (uint8/16/32/64) in the file's byte order and difference at that resolution with stride = samples_per_pixel. The 8-bit byte path stays as a fast special case since it was already correct. Tests cover reads of tifffile-produced predictor=2 TIFFs across uint16/int16/uint32/int32 and multi-band uint16, writer output verified by tifffile reading it back, and GPU/CPU parity for the multi-byte cases.
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test plan
pytest xrspatial/geotiff/tests/test_predictor_multisample.py(33 passed including new GPU+CPU multi-byte cases)pytest xrspatial/geotiff/tests/(533 passed; pre-existing matplotlib recursion failures in test_features plotting tests are unrelated to this change and reproduce on main)